<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        const api_books = 'http://ajax-api.itheima.net/api/books'
        const api_news = 'http://ajax-api.itheima.net/api/news'
        const api_robot = 'http://ajax-api.itheima.net/api/robot?spoken=你不好'

        // Promise.all()
        const fetch_book = fetch(api_books).then(res => res.json())
        // console.log(fetch_book)
        const fetch_news = fetch(api_news).then(res => res.json())
        // console.log(fetch_news)
        const fetch_robot = fetch(api_robot).then(res => res.json())
        // console.log(fetch_robot)

        // 所有的请求都成功了，返回给P
        const p = Promise.all([fetch_book,fetch_news,fetch_robot])
        
        console.log(p)


        // Promise.race()
        // 谁最快，最快的那个拿过来
        const p2 = Promise.race([fetch_book,fetch_news,fetch_robot])
        console.log(p2)

        // all获取所有，race获取第一个
    </script>
</body>
</html>